﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Interop.Security.AzRoles;

namespace System.Management.HyperV.AzMan
{
    internal class AzManStore
    {
        public IAzApplication2 GetStore(string storePath)
        {
            string connectionString = @"msxml://" + storePath;
            
            int flags = 0; // Microsoft.Interop.Security.AzRoles.tagAZ_PROP_CONSTANTS

            var azStore = new Microsoft.Interop.Security.AzRoles.AzAuthorizationStoreClass();
            azStore.Initialize(flags, connectionString);

            return azStore.OpenApplication2("Hyper-V services");
        }

        public static List<IAzRole> GetRoles(IAzApplication2 azStore)
        {
            var lstRoles = new List<IAzRole>();
            for (int ix = 1; ix <= azStore.Roles.Count; ix++)
            {
                lstRoles.Add((IAzRole)azStore.Roles[ix]);
            }
            return lstRoles;
        }
    }
}
